<?php
$adminRoleData = array();
$memberRoleData = array();
$customerRoleData = array();
if (isset($spaceRoleData)) {
    if (isset($spaceRoleData['adminRoleData']))
        $adminRoleData = $spaceRoleData['adminRoleData'];
    if (isset($spaceRoleData['memberRoleData']))
        $memberRoleData = $spaceRoleData['memberRoleData'];
    if (isset($spaceRoleData['customerRoleData']))
        $customerRoleData = $spaceRoleData['customerRoleData'];
}
?>
<style>
    @media (min-width: 768px){
        .roleList {
            margin-right: 0;
            margin-left: 0;
            background-color: #fff;
            border-color: #ddd;
            border-width: 1px;
            border-radius: 4px 4px 0 0;
            -webkit-box-shadow: none;
            box-shadow: none;
        }
    }
</style>
<legend>
    <h4><?php
        echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList'), array(
            'cooker' => 'BAEvent@showEventList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink('管理角色', array(
            'cooker' => 'BAEvent@showEventHome'
        ));
        ?>\
        机构角色列表 
    </h4>
</legend>
<div class="">
    <div class="roleList">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>分类</th>
                    <th>全名</th>
                    <th>应用</th>
                    <th>名称</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach ($customerRoleData as $id => $role) {
                    $appId = $role->appId;
                    $app = BApp::getAppById($appId);
                    $appClass = get_class($app);
                    $fullName = $role->getFullName();
                    $roleAlias = BARoleCooker::getRoleAliasByFullName($fullName);
                    $fullName = str_replace('app_root.', '', $fullName);
                    ?>
                    <tr>
                        <td><?php echo '客户角色'; ?></td>
                        <td><?php echo $fullName; ?></td>
                        <td><?php echo yii::t('site', $appClass); ?></td>
                        <td><?php echo $roleAlias; ?></td>
                        <td><?php
                            echo $control->getAjaxLink('加子角色', array(
                                'cooker' => 'BARoleCooker@showAddChildRole',
                                'roleId' => $id,
                                'htmlOptions' => array(
                                    'class' => ''
                            )));
                            ?> | 
                            <?php
                            echo $control->getAjaxLink('功能设置', array(
                                'cooker' => 'BARoleCooker@showRoleEventList',
                                'roleId' => $id,
                                'htmlOptions' => array(
                                    'class' => ''
                            )));
                            ?> <?php
                            if (!in_array($fullName, array(
                                        'app_customer',
                                        'app_customer.app_customer',
                                        'app_member',
                                        'app_member.app_member',
                                        'app_admin',
                                        'app_admin.app_admin',
                                    ))) {
                                echo '|';
                                echo $control->getAjaxLink('删除', array(
                                    'cooker' => 'BARoleCooker@deleteRole',
                                    'htmlOptions' => array(
                                        'class' => ''
                                )));
                            }
                            ?></td>
                    </tr>
                <?php } ?>
                <tr><td>---</td></tr>
                <?php
                foreach ($memberRoleData as $id => $role) {
                    $appId = $role->appId;
                    $app = BApp::getAppById($appId);
                    $appClass = get_class($app);
                    $fullName = $role->getFullName();
                    $roleAlias = BARoleCooker::getRoleAliasByFullName($fullName);
                    $fullName = str_replace('app_root.', '', $fullName);
                    $category = '成员角色';
                    ?>
                    <tr>
                        <td><?php echo '成员角色'; ?></td>
                        <td><?php echo $fullName; ?></td>
                        <td><?php echo yii::t('site', $appClass); ?></td>
                        <td><?php echo $roleAlias; ?></td>
                        <td><?php
                            echo $control->getAjaxLink('加子角色', array(
                                'cooker' => 'BARoleCooker@showAddChildRole',
                                'roleId' => $id,
                                'htmlOptions' => array(
                                    'class' => ''
                            )));
                            ?> | 
                            <?php
                            echo $control->getAjaxLink('功能设置', array(
                                'cooker' => 'BARoleCooker@showRoleEventList',
                                'roleId' => $id,
                                'htmlOptions' => array(
                                    'class' => ''
                            )));
                            ?> 
                            <?php
                            if (!in_array($fullName, array(
                                        'app_customer',
                                        'app_customer.app_customer',
                                        'app_member',
                                        'app_member.app_member',
                                        'app_admin',
                                        'app_admin.app_admin',
                                    ))) {
                                echo '|';
                                echo $control->getAjaxLink('删除', array(
                                    'cooker' => 'BARoleCooker@deleteRole',
                                    'htmlOptions' => array(
                                        'class' => ''
                                )));
                            }
                            ?></td>
                    </tr>
                <?php } ?>
                <tr><td>---</td></tr>
                <?php
                foreach ($adminRoleData as $id => $role) {
                    $appId = $role->appId;
                    $app = BApp::getAppById($appId);
                    $appClass = get_class($app);
                    $fullName = $role->getFullName();
                    $roleAlias = BARoleCooker::getRoleAliasByFullName($fullName);
                    $fullName = str_replace('app_root.', '', $fullName);
                    $category = '系统角色';
                    ?>
                    <tr>
                        <td><?php echo '系统角色'; ?></td>
                        <td><?php echo $fullName; ?></td>
                        <td><?php echo yii::t('site', $appClass); ?></td>
                        <td><?php echo $roleAlias; ?></td>
                        <td><?php
                            echo $control->getAjaxLink('加子角色', array(
                                'cooker' => 'BARoleCooker@showAddChildRole',
                                'roleId' => $id,
                                'htmlOptions' => array(
                                    'class' => ''
                            )));
                            ?> | 
                            <?php
                            echo $control->getAjaxLink('功能设置', array(
                                'cooker' => 'BARoleCooker@showRoleEventList',
                                'roleId' => $id,
                                'htmlOptions' => array(
                                    'class' => ''
                            )));
                            ?> 
                            <?php
                            if (!in_array($fullName, array(
                                        'app_customer',
                                        'app_customer.app_customer',
                                        'app_member',
                                        'app_member.app_member',
                                        'app_admin',
                                        'app_admin.app_admin',
                                    ))) {
                                echo '|';
                                echo $control->getAjaxLink('删除', array(
                                    'cooker' => 'BARoleCooker@deleteRole',
                                    'htmlOptions' => array(
                                        'class' => ''
                                )));
                            }
                            ?></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
</div>